package com.shaobufan.museum.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shaobufan.museum.mapper.MuseumNoticeMapper;
import com.shaobufan.museum.pojo.entity.MuseumNotice;
import com.shaobufan.museum.service.MuseumNoticeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 针对表【museum_notice(博物馆公告)】的数据库操作Service实现
 *
 * @author 17126
 * @date 2024-04-03 01:18:41
 */
@Service
public class MuseumNoticeServiceImpl extends ServiceImpl<MuseumNoticeMapper, MuseumNotice>
        implements MuseumNoticeService {

    @Resource
    MuseumNoticeMapper museumNoticeMapper;

    /**
     * 获取公告
     *
     * @return List MuseumNotice
     */
    @Override
    public List<MuseumNotice> getMuseumNotice() {
        QueryWrapper<MuseumNotice> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("notice_id");
        return museumNoticeMapper.selectList(queryWrapper);
    }

    /**
     * 添加公告
     *
     * @param noticeTitle 公告标题
     * @param noticeContent 公告内容
     * @return Boolean
     */
    @Override
    public Boolean addMuseumNotice(String noticeTitle, String noticeContent) {
        MuseumNotice museumNotice = new MuseumNotice();
        museumNotice.setNoticeTitle(noticeTitle);
        museumNotice.setNoticeContent(noticeContent);

        int inserted = museumNoticeMapper.insert(museumNotice);
        return inserted == 1;
    }
}